#ifndef Node_h
#define Node_h

#include "Thread.h"
#include "iSchedulable.h"
#include "Message.h"
#include <map>

#define INITCLOCK -1

using std::map;


typedef map<int, int> NEIGHBOURS;

class Mailer;
class System;
class SyncMessage;
class Node : public iSchedulable
{
public:
	Node(int id, System* sys, Mailer* mailer, int initClock);
	~Node(void);

	int getID();
	int getThreadID();
	void addNeighbour(int neighbourID);
	void setClock(int neighbourID, int clock);
	void setOwnClock(int clock);
	int getClock();
	void sendClock(int id);
	void syncMessageProc(SyncMessage* msg);
	bool isInSync();
	static void* algorithm(void* arg);
	int getTimeRequest();
private:
	int m_id;
	System* m_system;
	Mailer* m_mailer;
	Thread* m_node;
	NEIGHBOURS* m_neighbours;
	int m_clock;
	bool m_shouldRun;

	void sendClockToAll();
};

#endif
